package com.server;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 创建一个服务端
 */
public class Server {


    //维护一个socket对象
    private Socket socket;

    public static void main(String[] args) throws IOException {
        System.out.println("== myTomcat start===");
        ServerSocket serverSocket = new ServerSocket(9999);
        //因为这里是一直对请求进行接收的，所以应该是死循环
        while (true) {
            Socket socket = serverSocket.accept();
            Handler handler = new Handler(socket);
            //启动多线程
            handler.start();
        }

        //测试解析浏览器的请求：
        // 简易版的服务器 ，读取真正浏览器发来的请求
//        ServerSocket serverSocket=new ServerSocket(9999);
//        //接受请求
//        Socket socket = serverSocket.accept();
//        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//        String value = reader.readLine();
//        //循环读取内容太
//        while (value!=null && ""!=value){
//            System.out.println(value);
//            value=reader.readLine();
//        }
        //浏览器真正的消息  GET /index?username=hsc&pass=17 HTTP/1.1 这样的参数，需要进行解析
//        解析一个请求得到的完整信息：
//        GET /index?username=hsc&pass=17 HTTP/1.1
//        Host: localhost:9999
//        Connection: keep-alive
//        sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"
//        sec-ch-ua-mobile: ?0
//        sec-ch-ua-platform: "Windows"
//        Upgrade-Insecure-Requests: 1
//        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
//        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
//        Sec-Fetch-Site: none
//        Sec-Fetch-Mode: navigate
//        Sec-Fetch-User: ?1
//        Sec-Fetch-Dest: document
//        Accept-Encoding: gzip, deflate, br
//        Accept-Language: zh-CN,zh;q=0.9
    }


}